import Vue from 'vue'
import Router from 'vue-router'
import store from '@store'
// import { getToken } from '@utils/auth'

Vue.use(Router)

export const constantRoutes = [{
	path: '/',
	name: 'home',
	component: () => import('@/views/home/home'),
	redirect: {
		name: 'index'
	},
	children: [
		// 首页
		{
			path: '/index',
			component: () => import('@/views/pages/index'),
			name: 'index'
		},
		{
			path: '/removeToken',
			component: () => import('@/views/pages/removeToken'),
			name: 'removeToken'
		}
	]
}]

const createRouter = () => new Router({
	// mode: 'history', // require service support
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})

const router = createRouter()

// const hasToken = getToken()

// router.beforeEach(async(to, from, next) => {
//   if (to.path === '/login' || to.path === '/register' ) {
// 	  next()
//   } else {
// 	 if (store.state.token && store.state.token !== '' && store.state.token !== undefined) {
// 	 	  next()
// 	 } else {
// 	 	  next('login')
// 	 } 
//   }
  
// })

router.afterEach((to, from, next) => {
  window.scrollTo(0, 0)
})

export default router
